package cn.itcast.order.service;

import cn.itcast.feignclient.user.UserServiceFeignClient;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    //private final static String USER_URL = "http://localhost:8081/user/";
    private final static String USER_URL = "http://userservice/user/";
    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private RestTemplate restTemplate;//普通的发送http请求的工具

    @Autowired
    private UserServiceFeignClient userServiceFeignClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        //String url=USER_URL+order.getUserId();
        //User user = restTemplate.getForObject(url, User.class);
        //String s = restTemplate.getForObject(url, String.class);
        // 4.返回
        order.setUser(userServiceFeignClient.getById(order.getUserId()));
        return order;
    }
}
